from functools import wraps
from flask import jsonify
from app import redis_client

def cache_decorator(expire_seconds=3600):
    def decorator(f):
        @wraps(f)
        def decorated_function(*args, **kwargs):
            cache_key = f"{f.__name__}:{str(args)}:{str(kwargs)}"
            
            cached_data = redis_client.get(cache_key)
            if cached_data:
                return jsonify(cached_data)
            
            result = f(*args, **kwargs)
            
            redis_client.setex(cache_key, expire_seconds, str(result))
            
            return result
        return decorated_function
    return decorator 